package view.panel.play
{
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.text.TextField;
	import flash.text.TextFormat;
	
	import global.Resource;
	
	import utils.TextTool;
	
	public class RecordCard extends Sprite
	{
		private var title:TextField;
		private var count:TextField;
		private var bg:DisplayObject;
		
		public function RecordCard()
		{
			initBg();
			initTitle();
			initCount();
		}
		
		private function initCount():void
		{
			count = TextTool.getTextField(30,20,10,0,false,false,"right");
			count.y = 20;
			addChild(count);
		}
		
		private function initBg():void
		{
			bg = Resource.getImg("card_bg",true);
			bg.scaleX = bg.scaleY = .65;
			addChild(bg);
		}
		
		private function initTitle():void
		{
			title = TextTool.getTextField(30,60,20,0xFF0000,false,true);
			title.y = -4;
			title.x = -1;
			addChild(title);
		}
		
		public function updateTitle(v:int):void
		{
			var value:String = v.toString();
			if (v > 10)
			{
				switch (v)
				{
					case 11:
						value = "J";
						break;
					case 12:
						value = "Q";
						break;
					case 13:
						value = "K";
						break;
					case 14:
						value = "A";
						break;
					case 15:
						value = "2";
						break;
					case 16:
						value = "JOKER";
						//title.width = 12;
						//title.multiline = true;
						//title.wordWrap = true;
						title.y = 0;
						var tf:TextFormat = new TextFormat();
						tf.size = 8;
						tf.bold = true;
						tf.letterSpacing =0;
					
						tf.leading = -2;
						title.defaultTextFormat = tf;
						
						break;
				}
			}
			
			title.text = value;
		}
		
		public function updateCount(v:String):void
		{
			if (int(v) > 0 )
			{
				count.htmlText = "x<font color='#FF0000'><b>" + v + "</b></font>";
			}
			else
			{
				count.htmlText = "x" + v;
			}
		}
	}
}